package com.bondmatch.demo.controller;

import com.bondmatch.demo.model.TransRequest;
import com.bondmatch.demo.utils.DefaultResponseBody;
import com.bondmatch.demo.service.MatchResultService;
import com.bondmatch.demo.utils.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/bond_match")
public class MatchResultController {

    @Resource
    private MatchResultService matchResultService;

    /**
     * 匹配结果展示页面，按id降序排列，最新匹配的优先显示
     *
     * @return
     */
    @RequestMapping("/result")
    @ResponseBody
    public DefaultResponseBody getMatchResult(int pageNum, int pageSize) {
        DefaultResponseBody resultMap = new DefaultResponseBody();
        resultMap.setCode(200);
        resultMap.setMessage("匹配结果展示成功");
        Pager<TransRequest> pager = matchResultService.findByPager(pageNum, pageSize);
        List<TransRequest> list = pager.getRows();
        HashMap<String, Object> map = new HashMap<>();
        map.put("requests", list);
        map.put("count", pager.getTotal());
        resultMap.setData(map);
        return resultMap;
    }
}
